package com.lzy.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                // 文档主体信息
                .apiInfo(apiInfo())
                // 接口选择器
                .select()
                // 告诉springfox哪些接口要生成swagger文档(扫描该包下的API注解)
                .apis(RequestHandlerSelectors.basePackage("com.lzy.example.controller"))
                // 设置哪些接口生成在swagger文档上（any()——所有controller下的接口）
                .paths(PathSelectors.any())
                .build();

    }


    //api接口文档主体信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // API文档标题
                .title("Spring Data JPA学习Api手册")
                // 描述
                .description("学习使用Spring Boot整合Jpa框架")
                // 版本
                .version("v1.0")
                // 作者信息
                .contact(new Contact("lzy_『O』", "https://blog.csdn.net/weixin_44117737?spm=1010.2135.3001.5421", "632812075@qq.com"))
                .build();
    }
}
